function MyKeyPressFcn( action )

if nargin < 1
    ud.hFig = figure;
    set( ud.hFig, 'KeyPressFcn', [mfilename ' KeyPressFcn'] );
    set( ud.hFig, 'UserData', ud );
    action = 'initialize';
end;

switch action

case 'initialize'

    ud = get( gcf, 'UserData' );

    lblKeyChar.style = 'text'; 
    lblKeyChar.units = 'normalized'; 
    lblKeyChar.string = 'Key char: '; 
    lblKeyChar.position = [0.05 0.95 0.10 0.04]; 
    ud.lblKeyChar = uicontrol( lblKeyChar );
    
    edtKeyChar.style = 'edit';
    edtKeyChar.enable = 'off';
    edtKeyChar.units = 'normalized'; 
    edtKeyChar.position = [0.20 0.95 0.10 0.04]; 
    ud.edtKeyChar = uicontrol( edtKeyChar );

    lblKeyCode.style = 'text'; 
    lblKeyCode.string = 'Key code: '; 
    lblKeyCode.units = 'normalized'; 
    lblKeyCode.position = [0.05 0.90 0.10 0.04]; 
    ud.lblKeyCode = uicontrol( lblKeyCode );
    
    edtKeyCode.style = 'edit'; 
    edtKeyCode.enable = 'off';
    edtKeyCode.units = 'normalized'; 
    edtKeyCode.position = [0.20 0.90 0.10 0.04]; 
    ud.edtKeyCode = uicontrol( edtKeyCode );
    
    set( ud.hFig, 'UserData', ud );

case 'KeyPressFcn'

    ud = get( gcf,'UserData' );
    chCurr = get( ud.hFig, 'CurrentCharacter' );
    
    set( ud.edtKeyChar, 'String', chCurr );
    set( ud.edtKeyCode, 'String', int2str(chCurr) );

%    if( strcmp( int2str(chCurr), '28') )
%        set( ud.edtKeyCode, 'String', '<-' );
%    elseif( strcmp( int2str(chCurr), '29') )
%        set( ud.edtKeyCode, 'String', '->' );
%    end;
    
otherwise
    
    msgbox( ['Unknown action: ''' action ''''], mfilename );

end;

return;